package com.leetcode.LC;


import java.util.LinkedList;
import java.util.Queue;

public class LC566 {
    public int[][] matrixReshape(int[][] nums, int r, int c) {

        if (r * c != nums.length * nums[0].length) {
            return nums;
        }
        int[][] ints = new int[r][c];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums[0].length; j++) {
                queue.add(nums[i][j]);
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ints[i][j] = queue.poll();
            }
        }

        return ints;

    }

}
